﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Sample
{
    public class CombatResultsTable
    {
        private static readonly CombatResult[] Progression = new[]
                                                                 {
                                                                     CombatResult.AttackerEliminated,
                                                                     CombatResult.AttackerEliminated,
                                                                     CombatResult.AttackerRouted,
                                                                     CombatResult.AttackerRouted,
                                                                     CombatResult.AttackerStopped,
                                                                     CombatResult.AttackerStopped,
                                                                     CombatResult.Exchange,
                                                                     CombatResult.Exchange,
                                                                     CombatResult.DefenderRouted,
                                                                     CombatResult.DefenderWithdrawls,
                                                                     CombatResult.DefenderWithdrawls,
                                                                     CombatResult.DefenderEliminated,
                                                                     CombatResult.DefenderEliminated,
                                                                     CombatResult.DefenderEliminated,
                                                                     CombatResult.DefenderEliminated,
                                                                     CombatResult.DefenderEliminated
                                                                 };
        private static readonly Dictionary<CombatRatio, CombatResult[]> Table = new Dictionary<CombatRatio, CombatResult[]>(10);
        static CombatResultsTable()
        {
            for (Int32 i = -4; i < 0; i++)
            {
                Table.Add(new CombatRatio(1, Math.Abs(i)), Progress(i));
            }
            for (int i = 0; i < 6; i++)
            {
                Table.Add(new CombatRatio(i + 2, 1), Progress(i));
            }
        }

        public CombatResult DetermineResult(Int32 diceRollValue, CombatRatio ratio)
        {
            var resultTack = Table[ratio];
            CombatResult result = resultTack[diceRollValue - 1];

            return result;
        }

        private static CombatResult[] Progress(Int32 startAt)
        {
            startAt += 4;

            var e = Progression.Skip(startAt).Take(6);
            CombatResult[] result = e.ToArray();

            return result;
        }
    }
}
